﻿using System;
using System.Windows;
using System.Windows.Controls;
using SoftSource.Common;
using SoftSource.MVVMC;
using SoftSource.Reactive;
using SoftSource.Timecard.Resources;
using SoftSource.Timecard.ViewModelInterfaces;

namespace SoftSource.Timecard.Views
{
    public sealed partial class EntryProjectCategoryAssociationEditor : UserControl, IView<IEntryProjectCategoryAssociationEditorViewModelConsume>
    {
        public EntryProjectCategoryAssociationEditor()
        {
            InitializeComponent();

            Loaded += new RoutedEventHandler(EntryProjectCategoryAssociationEditor_Loaded);
        }

        #region Events

        void EntryProjectCategoryAssociationEditor_Loaded(object sender, RoutedEventArgs e)
        {
            if (this.ViewModel != null)
            {
                this.Busy.BusyContent = ApplicationStrings.LoadingMessage;
                this.Busy.IsBusy = true;

                this.ViewModel.Load // Load the data required to use this ViewModel
                    .Nullable()
                    .Subscribe(unit => this.Busy.IsBusy = false);
            }
        }

        private void Close_Click(object sender, RoutedEventArgs e)
        {
            this.ViewModel.Completed.TryInvoke();
        }

        #endregion Events

        #region IView<IEntryProjectCategoryAssociationEditorViewModelConsume> Members

        public IEntryProjectCategoryAssociationEditorViewModelConsume ViewModel
        {
            get { return this.DataContext as IEntryProjectCategoryAssociationEditorViewModelConsume; }
            set { this.DataContext = value; }
        }

        #endregion
    }
}
